<template>
    <transition name="slide-up">
        <div class="setting-wrapper" v-show="menuVisible && settingVisible == 0">
            <div class="setting-font-size">
                <div class="preview" :style="{fontSize: fontSizeList[0].fontSize + 'px'}">A</div>
                <div class="select">
                    <div class="select-wrapper" v-for="(item,index) in fontSizeList" :key="index" @click="setFontSize(item.fontSize)">
                        <div class="line"></div>  
                        <div class="point-wrapper">
                            <!-- 大点中包裹小点 -->
                            <div class="point" v-show="defaultFontSize === item.fontSize">
                                <div class="small-point"></div>
                            </div>
                        </div>
                        <div class="line"></div>
                    </div>
                </div>
                <div class="preview" :style="{fontSize: fontSizeList[fontSizeList.length - 1].fontSize + 'px'}">A</div>
            </div>
            <div class="setting-font-family" @click="showFontFamilyPopup">
                 <div class="setting-font-family-text-wrapper">
                     <!-- 这里 defaultFontFamily 直接从vuex中引用，不用加this-->
                     <span class="setting-font-family-text" >{{ defaultFontFamily }}</span>
                 </div>
                 <div class="setting-font-family-icon-wrapper">
                     <span class="icon-forward"></span>
                 </div>
            </div>
        </div>
    </transition>
</template>

<script>
import { ebookMixin } from '../../utils/mixin'
import { FONT_SIZE_LIST } from '../../utils/book'
import { saveFontSize } from '../../utils/localStorage'
export default {
    mixins: [ebookMixin],
    data() {
        return {
            fontSizeList: FONT_SIZE_LIST,
        };
    },

    mounted() {
        
    },

    methods: {
        showFontFamilyPopup() { //设置字体
            this.setFontFamilyVisible(true)
        },
        setFontSize(fontSize) { //设置字体大小
            // console.log('this.defaultFontSize',this.defaultFontSize)
            this.setDefaultFontSize(fontSize)//设置默认字体大小
            // console.log('this.defaultFontSize',this.defaultFontSize)
            saveFontSize(this.fileName,fontSize)//将默认字体大小保存到本地,方便刷新后保留
            this.currentBook.rendition.themes.fontSize(fontSize + 'px') //改变电子书字体大小
        }
    },
};
</script>

<style lang="scss" scoped>
@import '../../assets/styles/global.scss';
    .setting-wrapper { 
        position: absolute;
        bottom: px2rem(48);
        left: 0;
        width: 100%;
        display: flex;
        flex-direction: column;
        height: px2rem(90);
        z-index: 101;
        background: white;
        box-shadow: 0 px2rem(-8) px2rem(8) rgba(0,0,0,.15);
        .setting-font-size { 
            display: flex;
            flex: 2;
            height: 100%;
            .preview { 
                flex: 0 0 px2rem(40);
                @include center;
            }
            .select { 
                display: flex;
                flex: 1;
                align-items: center;
                .select-wrapper { 
                    display: flex;
                    flex: 1;
                    align-items: center;
                    &:first-child { //第一个select-wrapper
                        .line { 
                            &:first-child { //第一条line
                                border-top: none;
                            }
                        }
                    }
                    &:last-child { //最后一个select-wrapper
                        .line { 
                            &:last-child {  //最后一条line
                                border-top: none;
                            }
                        }
                    }
                    .line { 
                        flex: 1;
                        height: 0;
                        border-top: px2rem(1) solid #ccc;
                    }
                    .point-wrapper {
                        position: relative;
                        flex: 0 0 0;
                        width: 0;
                        height: px2rem(7);
                        border-left: px2rem(1) solid #ccc; 
                        .point { 
                            position: absolute;
                            top: px2rem(-8);
                            left: px2rem(-10);
                            width: px2rem(20);
                            height: px2rem(20);
                            border-radius: 50%;
                            background: white;
                            border: px2rem(1) solid #ccc;
                            box-shadow: 0 px2rem(4) px2rem(4) raga(0,0,0,.15);
                            @include center;
                            .small-point { 
                                width: px2rem(5);
                                height: px2rem(5);
                                border-radius: 50%;
                                background: black;
                            }
                        }
                    }
                }
            }
        }
        .setting-font-family { 
            flex: 1;
            font-size: px2rem(14);
            @include center;
            .setting-font-family-text-wrapper {
                @include center; 
                .setting-font-family-text { 
                    
                }
            }
            .setting-font-family-icon-wrapper { 
                @include center; 
                .icon-forward { 

                }   
            }
        }
    }
</style>